<template>
  <div class="demo">
    <h1>组件演示</h1>
    
    <section class="section">
      <h2>卡片组件</h2>
      <div class="cards">
        <Card 
          title="Vue 3" 
          description="Vue 3带来了Composition API、更好的TypeScript支持等新特性。"
          image-src="https://picsum.photos/400/200?random=7"
          :clickable="true"
          @click="handleCardClick('Vue 3')"
        />
        <Card 
          title="Vite" 
          description="Vite是一个由原生ESM驱动的Web开发构建工具，提供极快的冷启动。"
          image-src="https://picsum.photos/400/200?random=8"
          :clickable="true"
          @click="handleCardClick('Vite')"
        />
      </div>
    </section>
    
    <section class="section">
      <h2>按钮组件</h2>
      <div class="buttons">
        <Button variant="primary" @click="handleButtonClick('primary')">主要按钮</Button>
        <Button variant="secondary" @click="handleButtonClick('secondary')">次要按钮</Button>
        <Button variant="danger" @click="handleButtonClick('danger')">危险按钮</Button>
        <Button variant="text" @click="handleButtonClick('text')">文字按钮</Button>
        <Button :disabled="true">禁用按钮</Button>
      </div>
    </section>

    <section class="section">
      <h2>工具函数演示</h2>
      <div class="utils-demo">
        <p>当前日期: <span v-text="currentDate"></span></p>
        <p>随机ID: <span v-text="randomId"></span></p>
        <Button @click="generateNewId">生成新ID</Button>
      </div>
    </section>
  </div>
</template>

<script>
import { ref } from 'vue'
import Card from '../components/Card.vue'
import Button from '../components/Button.vue'
import { formatDate, generateId } from '../utils/helpers.js'

export default {
  name: 'Demo',
  components: {
    Card,
    Button
  },
  setup() {
    const currentDate = ref(formatDate(new Date()))
    const randomId = ref(generateId())
    
    const handleCardClick = (title) => {
      alert(`您点击了 ${title} 卡片`)
    }
    
    const handleButtonClick = (variant) => {
      alert(`您点击了 ${variant} 按钮`)
    }
    
    const generateNewId = () => {
      randomId.value = generateId()
    }
    
    return {
      currentDate,
      randomId,
      handleCardClick,
      handleButtonClick,
      generateNewId
    }
  }
}
</script>

<style scoped>
.demo {
  max-width: 1200px;
  margin: 0 auto;
}

.demo h1 {
  text-align: center;
  margin-bottom: 3rem;
}

.section {
  margin-bottom: 3rem;
}

.section h2 {
  margin-bottom: 1.5rem;
  color: #2c3e50;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.utils-demo {
  padding: 1.5rem;
  background-color: #f8f9fa;
  border-radius: 8px;
}

.utils-demo p {
  margin-bottom: 1rem;
}

@media (max-width: 768px) {
  .cards {
    grid-template-columns: 1fr;
  }
  
  .buttons {
    flex-direction: column;
    align-items: flex-start;
  }
}
</style>